# 构建阶段
FROM golang:1.24-alpine AS builder
WORKDIR /app
COPY . .
RUN go mod download
# 编译时指定CGO_ENABLED=0，避免Alpine缺少动态链接库
RUN CGO_ENABLED=0 GOOS=linux go build -o dict-server cmd/web/main.go

# 运行阶段
FROM alpine:latest
WORKDIR /app
# 添加可执行权限
COPY --from=builder /app/dict-server /app/dict-server
RUN chmod +x /app/dict-server
CMD ["/app/dict-server"]
    